package com.mobi.Survey.uicomponents;

import java.util.StringTokenizer;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.mobi.Survey.controller.SurveyDetailPojo;

/**
 * 
 * <p>
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * CustomRadioGroup.java
 * 
 * 
 */
public class CustomRadioGroup extends RadioGroup
{
	private Context ctx;
	private LinearLayout ll;
	public static final String DELIM = "|";

	public CustomRadioGroup(Context context, SurveyDetailPojo sdp,
			boolean editable)
	{
		super(context);

		this.ctx = context;
		ll = new LinearLayout(ctx);

		ll.setOrientation(LinearLayout.VERTICAL);
		if (sdp.getControlText() != null && sdp.getControlText().length() > 0)
		{

			CustomTextView txt = new CustomTextView(ctx);
			txt.setCustomColor(sdp);
			txt.setText(sdp.getControlText());
			ll.addView(txt);

		}
		String ctr_txt = sdp.getControlParameter();
		StringTokenizer st = new StringTokenizer(ctr_txt, DELIM);
		CustomRadioButton selection = null;
		while (st.hasMoreTokens())
		{
			String ctrl_txt = st.nextToken();
			CustomRadioButton crb = new CustomRadioButton(ctx);
			if (sdp.getUserValue().equalsIgnoreCase(ctrl_txt.trim()))
			{
				selection = crb;
				selection.setId(50);

			}
			crb.setText(ctrl_txt.trim());
			if (!editable)
				crb.setEnabled(false);
			this.addView(crb);
		}
		if (selection != null)
			this.check(selection.getId());
		ll.addView(this);

	}

	public View getView()
	{
		return ll;
	}

}
